package com.atguigu.gmall.order.config;

import com.atguigu.gmall.common.mqconstant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wk
 * @create 2021-09-14 9:51
 */
@Configuration
public class OrderInfoConfig {

    @Bean
    public Exchange orderInfoExchange() {
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL, "x-delayed-message", true, false, arguments);
    }

    @Bean
    public Queue orderInfoQueue() {
        return QueueBuilder.durable(MqConst.QUEUE_ORDER_CANCEL).build();
    }

    @Bean
    public Binding bindingOderInfoQueueToOrderInfoExchange(
            @Qualifier("orderInfoQueue") Queue orderInfoQueue,
            @Qualifier("orderInfoExchange") Exchange orderInfoExchange) {
        return BindingBuilder.bind(orderInfoQueue).to(orderInfoExchange).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }
}
